package demo1;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {

        public void merge(int[] nums1, int m, int[] nums2, int n) {
            int i = m -1;
            int j= n -1;
            int t = n + m - 1;
            while (i >= 0 && j >= 0){
                if(nums1[i] < nums2[j]){
                    nums1[t] = nums2[j];
                    t--;
                    j--;
                }
                else {
                    nums1[t] = nums1[i];
                    i--;
                    t--;
                }
            }
            while (j >= 0){
                nums1[t] = nums2[j];
                j--;
                t--;
            }

        }
    }

public class Test {
    public static void main(String[] args) {
        Solution solution =  new Solution();
        int [] nums1 = {1,2,3,0,0,0};
        int [] nums2 = {2,5,6};
        solution.merge(nums1,3,nums2,3);
        System.out.println(Arrays.toString(nums1));

    }
}
